package com.example.myapplication.service;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.myapplication.MainActivity;
import com.example.myapplication.R;

public class IntentServiceActivity extends AppCompatActivity {
    Button btn1;
    Button btn2;
    Intent intent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent_service);

        btn1 = findViewById(R.id.IntentService_btn1);
        btn2 = findViewById(R.id.IntentService_btn2);
        btn1.setOnClickListener(new MClick());
        btn2.setOnClickListener(new MClick());

    }

    private class MClick implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            intent = new Intent(IntentServiceActivity.this,MyIntentService.class);

            switch (v.getId()){
                case R.id.IntentService_btn1:
                    Log.i("test", "--------------IntentService_btn1");
                    intent.putExtra("num","1");
                    break;
                case R.id.IntentService_btn2:
                    Log.i("test", "--------------IntentService_btn2");
                    intent.putExtra("num","2");
                    break;
            }
            startService(intent);
        }
    }
}